package Servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Logic.CardLogic;
import Model.CardBean;

@SuppressWarnings("serial")
public class CardServlet extends HttpServlet {
	
	 @Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {      
		 response.setCharacterEncoding("utf-8");		
		 response.setContentType("text/html;charset=utf-8");		
		 PrintWriter out = response.getWriter();
		 String opType = request.getParameter("opType");  
	}
		 
	    // 接收客户端浏览器的POST请求，由Service方法跳转
	    @Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
	    	response.setCharacterEncoding("utf-8");
	    	response.setContentType("text/html;charset=utf-8");
	    	PrintWriter out = response.getWriter();
	    	String opType = request.getParameter("opType"); 
	    	
	    	if (opType.equals("getCard")){        	        	
	    		int CardID = Integer.parseInt(request .getParameter("ID")); 	            
	    		CardLogic cardlogic = new CardLogic();
				List<CardBean> listCard = cardlogic.getCard(CardID);				
				if (listCard!=null){
					 HttpSession session = request.getSession();            	   
					 session.setAttribute("getCard", listCard);
				}
			}else if (opType.equals("getCardByName")){        	        	
	    		String CardName = request .getParameter("CardName"); 	            
	    		CardLogic cardlogic = new CardLogic();
				List<CardBean> listCard = cardlogic.getCardByName(CardName);				
				if (listCard!=null){
					 HttpSession session = request.getSession();            	   
					 session.setAttribute("getCardByName", listCard);
				}
			}
	}
}
